package com.xlf.service.base.controller.client;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.xlf.common.core.annotation.Anonymous;
import com.xlf.common.core.annotation.RepeatSubmit;
import com.xlf.common.core.pojo.mode.AjaxResult;
import com.xlf.common.core.pojo.mode.BaseController;
import com.xlf.pojo.base.Problem;
import com.xlf.service.base.manager.ProblemCommonService;
import com.xlf.service.base.pojo.dto.ProblemReqDTO;
import com.xlf.service.base.pojo.vo.ProblemDetailVO;
import com.xlf.service.base.pojo.vo.ProblemVO;
import com.xlf.service.base.service.ProblemCaseService;
import com.xlf.service.base.service.ProblemListService;
import com.xlf.service.base.service.ProblemService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

/**
 * @Author xlf 2734029211@qq.com
 * @Date 2023/10/3 10:22
 * @Description: TODO
 * @Version 1.0
 */
@RestController
@RequestMapping("/base/problem")
public class ProblemController extends BaseController {

    @Autowired
    ProblemService problemService;

    @Autowired
    ProblemCommonService problemCommonService;

    @Autowired
    ProblemCaseService problemCaseService;

    /**
     * 获取题目列表
     * @param reqDTO
     * @return
     */
    @Anonymous
    @PostMapping("/list")
    public AjaxResult list(@RequestBody ProblemReqDTO reqDTO){
        return success(problemService.getProblemVOList(reqDTO));
    }

    /**
     * 获取最近题目
     * @return
     */
    @Anonymous
    @GetMapping("/new/list")
    public AjaxResult list(){
        List<ProblemVO> list = problemService.getRecentlyProblemVOList();
        return success(list);
    }

    /**
     * 获取题目详情
     * @param id
     * @return
     */
    @Anonymous
    @GetMapping("/{id}")
    public AjaxResult query(@PathVariable(value = "id") Long id){
        return success(problemCommonService.problemDetailVOCommander(id));
    }


    /**
     * @Description 获取单个提交记录的详情
     */
    @RepeatSubmit(interval = 500,message = "操作频繁，稍后重试",ignoreParams = true)
    @PreAuthorize("@ss.hasPermi('base:problem:download')")
    @GetMapping("/download/problemCase/{pid}/{id}")
    public void downloadTestcase(@PathVariable(value = "pid") Long pid,@PathVariable(value = "id") Long id) throws IOException {
        problemCaseService.downloadTestcase(pid,id);
        return;
    }
}
